

import java.io.Serializable;

public class ClientInfo implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5477618543347295806L;
	private String surveyAnswers[][];
	public String subjectNumber;
	public boolean existed = false;
	public int index;
	public int oldIndex;
	public int guiIndex;
	public int roundNum = 1;
	private int status;
	// [0] = index, [1] = s1 answer, [2] = s2 answer, [3] = s3 answer, s[4] =
	// time1, s[5] = time2, s[6] = time3, s[7] = order
	
	public Pledge pledge;
	public double[][] choices;
	public boolean[] quizAnswers;
	public double payment = 0; 

	// Client uses this constructor
	public ClientInfo(String[][] str) {
		surveyAnswers = str;
		status = Pledge.INSTRUCTIONS;
		choices = null;
		quizAnswers = null;
	}

	public String[][] getInfo() {
		return surveyAnswers;
	}

	public int getStatus() {
		return status;
	}

	public void setAnswers(String[][] s) {
		surveyAnswers = s;
	}

	public void setStatus(int s) {
		if (s > -1 && s < 8)
			status = s;
	}

	public int[][] sort() {

		int[][] sorted = new int[choices.length][choices[0].length];

		for (int i = 0; i < choices.length; i++) {
			for (int j = 0; j < choices[i].length; j++) {
				sorted[i][j] = (int) choices[i][j];
			}
		}

		quickSort(sorted, 0, sorted.length - 1);
		return sorted;
	}

	private static void quickSort(int[][] array, int left, int right) {
		if (right > left) {
			int index = partition(array, left, right, left);
			quickSort(array, left, index - 1);
			quickSort(array, index + 1, right);
		}
		return;
	}

	private static int partition(int[][] array, int left, int right,
			int pivotIndex) {
		int pivot = array[pivotIndex][0];
		int index = left;
		swap(array, pivotIndex, right);
		for (int i = left; i < right; i++) {
			if (array[i][0] < pivot) {
				swap(array, i, index++);
			}
		}
		swap(array, index, right);
		return index;
	}

	private static void swap(int[][] array, int s1, int s2) {
		int[] temp = array[s1];
		array[s1] = array[s2];
		array[s2] = temp;
		return;
	}

	public void attachPledge(Pledge p) {
		this.pledge = p;
	}
}
